/**
 * @program: LeetCode
 * @description: LeetCode :
 * @author: WXY
 * @create: 2023-01-03 16:56
 * @Version 1.0
 **/
public class Num680_lemonadeChange {
    public static boolean lemonadeChange(int[] arr) {
        int five = 0;
        int ten = 0;
        for (int bill : arr) {
            if (bill == 5) {
                five++;
            } else if (bill == 10) {
                if (five == 0) return false;
                five--;
                ten++;
            } else {
                if (five > 0 && ten > 0) {
                    ten--;
                    five--;
                } else if (five >= 3) {
                    five -= 3;
                } else {
                    return false;
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        int[] arr = {5, 5, 5, 5, 10, 10, 10, 20};
        boolean b = lemonadeChange(arr);
        System.out.println(b);
    }
}
